#!/bin/bash

RET=0
if [ $# -ne 4 ];then
        echo -e "\e[31m参数1输入uin,参数2输入源服务器大区id!\e[0m"
	echo -e "\e[31m参数3输入目的服大区id，参数4输入目的服务器ID\e[0m"
        RET=1
fi

if [ ${RET} -eq "0" ];then
        TABLE=`expr $1 % 64`
        UIN=$1
        SET_ID=$2
        #IP=$3
        mysqldump -uroot -pqy22players -S /var/lib/mysql/mysql.sock -t --set-gtid-purged=OFF game_db_${SET_ID} role_attrib_${TABLE} -w "qy_uin=${UIN}" > ${UIN}_${TABLE}.sql


        TAR_SET_ID=$3
        TAR_GAME_SET_ID=$4
        SQL_CMD="mysql -uroot -pqy22players -A -e "
		${SQL_CMD} "delete from game_db_${TAR_SET_ID}.role_attrib_${TABLE} where qy_uin=${UIN};"
        ${SQL_CMD} "use game_db_${TAR_SET_ID};source ${UIN}_${TABLE}.sql;"
        ${SQL_CMD} "use game_db_${TAR_SET_ID};update role_attrib_${TABLE} set game_set_id=${TAR_GAME_SET_ID},create_set_id=${TAR_GAME_SET_ID},own_set_id=${TAR_GAME_SET_ID} where qy_uin=${UIN};"
		rm -f ${UIN}_${TABLE}.sql
fi


